package GUI窗体和Swing.事件处理机制.Swing常用事件处理;

import javax.swing.JFrame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;




//窗体事件处理





public class text {

    public static void main(String[] args) {
        JFrame jf = new JFrame();
        jf.setTitle("窗体事件处理");
        jf.setBounds(100,100,400,300);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
        jf.addWindowListener(new WindowListener() {
            @Override
            //窗口打开时触发事件
            public void windowOpened(WindowEvent e) {
                System.out.println("windowOpened->窗口打开时触发事件");
            }
            //窗口关闭时触发事件
            public void windowClosing(WindowEvent e) {
                System.exit(0);
                System.out.println("windowClosing->窗口关闭时触发事件");
            }

            @Override
            //窗口关闭后触发事件
            public void windowClosed(WindowEvent e) {
                System.out.println("windowClosed->窗口关闭后触发事件");

            }

            @Override
            //窗口最小化时触发事件
            public void windowIconified(WindowEvent e) {
                System.out.println("windowIconified->窗口最小化时触发事件");

            }

            @Override
            //窗口最大化时触发事件

            public void windowDeiconified(WindowEvent e) {
                System.out.println("windowDeiconified->窗口最大化时触发事件");

            }

            @Override
            //窗口被激活时触发事件
            public void windowActivated(WindowEvent e) {
                System.out.println("windowActivated->窗口被激活时触发事件");

            }

            @Override
            //窗口被取消激活时触发事件
            public void windowDeactivated(WindowEvent e) {
                System.out.println("windowDeactivated->窗口被取消激活时触发事件");

            }
        });
    }
}
